package example.file;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

/**
 * Created by lenovo on 2016/11/4 0004.
 * File 类的 createTempFile() 方法来创建临时文件
 */
public class CacheFile {
    public static void main(String[] args)
            throws Exception {
        File temp = File.createTempFile("pattern", ".suffix");
        //声明应用程序退出时候，则清除掉缓存文件
        temp.deleteOnExit();
        BufferedWriter out = new BufferedWriter(new FileWriter(temp));
        out.write("aString");
        System.out.println("临时文件已创建:");
        out.close();
    }
}
